package cn.rui.controller;

import cn.rui.websocket.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * @author 徽州大都督
 * @date 2021/05/19
 */
@Controller
public class TestController {

    @Autowired
    private WebSocket webSocket;


    //单独发
    @ResponseBody
    @GetMapping("/sendTo")
    public String sendTo(@RequestParam("userId") String userId, @RequestParam("msg") String msg) throws IOException {

        webSocket.sendMessageTo(msg,userId);

        return "推送成功";
    }


    //群发
    @ResponseBody
    @GetMapping("/sendAll")
    public String sendAll(@RequestParam("msg") String msg) throws IOException {

        String fromUserId = "system";//其实没用上
        webSocket.sendMessageAll (msg, fromUserId);

        return "推送成功";
    }

}
